﻿using B.S.Database.Domain.Entity;
using B.S.Database.ErrorCode;
using B.S.Database.Interface.Interface;
using B.S.Database.Read.Api.Application.Commands.Breeding;
using MediatR;

namespace B.S.Database.Read.Api.Application.CommandHandler.Breeding
{
    public class BreedingShowCommandHandler : IRequestHandler<BreedingShowCommands, Apiresult<List<Breeding_Information>>>
    {
        private readonly IBaseResotity<Breeding_Information> breedingRepo;

        public BreedingShowCommandHandler(IBaseResotity<Breeding_Information> BreedingRepo)
        {
            breedingRepo = BreedingRepo;
        }
        public Task<Apiresult<List<Breeding_Information>>> Handle(BreedingShowCommands request, CancellationToken cancellationToken)
        {
            Apiresult<List<Breeding_Information>> res = new Apiresult<List<Breeding_Information>>();
            res.Code = ApiEnums.成功;
            res.Message = ApiEnums.成功.ToString();
            var list = breedingRepo.GetAll().Where(c=>c.TraceabilityId==request.TraceabilityId);
            res.Data = list.ToList();
            return Task.FromResult(res);
        }
    }
}
